//
//  HiperTimer.m
//  Calibration
//
//  Created by ViKing Lai on 2018/1/24.
//  Copyright © 2018年 ViKing Lai. All rights reserved.
//

#import "HiperTimer.h"

@implementation HiperTimer

- (id)init
{
	return (self = [super init]);
}


- (int)durationMillisecond
{	
	if(gettimeofday(&tv, NULL) == 0)
		mStop = tv.tv_sec * 1000 + tv.tv_usec/1000;
	
	return (int)mStop - (int)mStart;
}

+ (void)delaySecond:(double)delaytime
{
	[self delayMillsecond: delaytime * 1000];
}

+ (void)delayMillsecond:(int)delaytime
{	
	HiperTimer* timer = [[HiperTimer alloc] init];

	[timer start];
	
	while (true)
	{
		if([timer durationMillisecond] >= delaytime)
		{
		    break;
		}
	}
}

- (void)start
{
	//time(&mStart);
	
	if(gettimeofday(&tv, NULL) == 0)
		mStart = tv.tv_sec * 1000 + tv.tv_usec/1000;
}

@end
